package com.fzh.controller.back;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fzh.pojo.entity.Cart;
import com.fzh.pojo.entity.OrderInfo;
import com.fzh.pojo.entity.Product;
import com.fzh.pojo.entity.User;
import com.fzh.pojo.utils.PageUtil;
import com.fzh.pojo.utils.ResponeMessageUtil;
import com.fzh.service.CartService;
import com.fzh.service.OrderInfoService;
import com.fzh.service.ProductService;
import com.fzh.service.UserService;

@Controller
@RequestMapping("/back/")
public class CartController {
	
	@Autowired
	private CartService cartService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private ProductService productService;
	
	@Autowired
	private OrderInfoService orderInfoService;
	
	@RequestMapping("/queryAllCart")
	@ResponseBody
	public ResponeMessageUtil queryAllCart(Integer page,Integer limit,String f_uid,String f_pid) {
		Integer setValue = PageUtil.getSetValue(page, limit);
		return ResponeMessageUtil.ok(cartService.queryCartCounts(f_uid,f_pid), cartService.queryAllCart(setValue,limit,f_uid,f_pid));
	}
	
	/**
	 * 查询出所有用户信息展示到购物车列表内的下拉框
	 * @return
	 */
	@RequestMapping("/queryAllUserWitchCartSelect")
	@ResponseBody
	public List<User> queryAllUserWitchCartSelect(){
		return userService.queryAllUserWitchOrderIndoSelect();
	}
	
	/**
	 * 查询出所有商品的信息展示到购物车列表内的下拉框中
	 * @return
	 */
	@RequestMapping("/queryAllProductWitchCartSelect")
	@ResponseBody
	public List<Product> queryAllProductWitchCartSelect(){
		return productService.queryAllProductWitchImagesSelect();
	}
	
	/**
	 * 查询出商品信息根据id，用于把数据添加到购物车页面input标签内
	 * @param id
	 * @return
	 */
	@RequestMapping("/queryProductByIdWitchCartInput/{id}")
	@ResponseBody
	public Product queryProductByIdWitchCartInput(@PathVariable("id")Integer id){
		return productService.queryProductByIdWitchCartInput(id);
	}
	
	/**
	 * 查询出商品订单的信息根据id，用于把数据显示到购物车页面input框内
	 * @param id
	 * @return
	 */
	@RequestMapping("/queryOrderInfoByIdWitchCartInput/{id}")
	@ResponseBody
	public OrderInfo queryOrderInfoByIdWitchCartInput(@PathVariable("id") Integer id) {
		return orderInfoService.queryOrderInfoByIdWitchCartInput(id);
	}
	
	/**
	 * 添加一个购物车
	 * @param cart
	 * @return
	 */
	@RequestMapping("/addCart")
	@ResponseBody
	public Boolean addCart(Cart cart) {
		return cartService.addCart(cart);
	}
	
	/**
	 * 编辑购物车的信息
	 * @param cart
	 * @return
	 */
	@RequestMapping("/editCartById")
	@ResponseBody
	public Boolean editCartById(Cart cart) {
		return cartService.editCartById(cart);
	}
	
	/**
	 * 根据ids批量删除购物车
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delAllCartByIds")
	@ResponseBody
	public Boolean delAllCartByIds(@RequestParam("ids") String ids) {
		return cartService.delAllCartByIds(ids);
	}
	
	/**
	 * 根据id删除单个的购物车
	 * @param id
	 * @return
	 */
	@RequestMapping("/delCartById/{id}")
	@ResponseBody
	public Boolean delCartById(@PathVariable("id") Integer id) {
		return cartService.delCartById(id);
	}

}
